/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package proyectocallcentergrupo6;

import java.awt.BorderLayout;
import javax.swing.*;

/**
 *
 * @author Isaac
 */
public class MenuGeneral extends javax.swing.JFrame {
    Usuario c = null;
    //Con esto se habilitaran los botones
    private boolean modificar_servicio, buscar, modificar_general;
    final String Error_Permiso = "Atencion\nNo tiene los permisos necesarios para ejecutar este comando.";
    /**
     * Creates new form MenuGeneral
     */
    public MenuGeneral() {
        initComponents(); 
        fondo();
    }
    public void permisos(){
        //La ventana login activara estos permisos
        
        //Administrador puede modificar TODO
        if("administrador".equals(c.getCargo())){
            this.modificar_general = true;
            this.modificar_servicio = true;
            this.buscar = true;
        }
        //Supervisor solo puede buscar
        else if("supervisor".equals(c.getCargo())){
            this.modificar_general = false;
            this.modificar_servicio = false;
            this.buscar = true;
        }
        //Ejecutivo solo puede modificar servicios
        else if("ejecutivo".equals(c.getCargo())){
            this.modificar_general = false;
            this.modificar_servicio = true;
            this.buscar = false;
        }
    }

    public Usuario getC() {
        return c;
    }

    public void setC(Usuario c) {
        this.c = c;
    }
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        JDesk = new javax.swing.JDesktopPane();
        CMDBuscar = new javax.swing.JButton();
        CMDServ = new javax.swing.JButton();
        CMDconfigUser = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        CMDconfigClie = new javax.swing.JButton();
        CMDCierreSesion = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowOpened(java.awt.event.WindowEvent evt) {
                formWindowOpened(evt);
            }
        });

        CMDBuscar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/proyectocallcentergrupo6/Find.png"))); // NOI18N
        CMDBuscar.setText("Buscar Cliente");
        CMDBuscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CMDBuscarActionPerformed(evt);
            }
        });
        JDesk.add(CMDBuscar);
        CMDBuscar.setBounds(20, 80, 210, 70);

        CMDServ.setIcon(new javax.swing.ImageIcon(getClass().getResource("/proyectocallcentergrupo6/plus_2.png"))); // NOI18N
        CMDServ.setText("Modificar Servicios");
        CMDServ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CMDServActionPerformed(evt);
            }
        });
        JDesk.add(CMDServ);
        CMDServ.setBounds(20, 160, 210, 70);

        CMDconfigUser.setIcon(new javax.swing.ImageIcon("C:\\Users\\Isaac\\Documents\\NetBeansProjects\\trunk\\ProyectoCallCenterGrupo6\\src\\proyectocallcentergrupo6\\Icono_2.png")); // NOI18N
        CMDconfigUser.setText("Configurar Usuarios");
        CMDconfigUser.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CMDconfigUserActionPerformed(evt);
            }
        });
        JDesk.add(CMDconfigUser);
        CMDconfigUser.setBounds(20, 320, 210, 69);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel1.setText("BIENVENIDO A COMUNICATE");
        JDesk.add(jLabel1);
        jLabel1.setBounds(120, 10, 171, 22);

        CMDconfigClie.setIcon(new javax.swing.ImageIcon("C:\\Users\\Isaac\\Documents\\NetBeansProjects\\trunk\\ProyectoCallCenterGrupo6\\src\\proyectocallcentergrupo6\\tuerca_2.png")); // NOI18N
        CMDconfigClie.setText("Configurar Clientes");
        CMDconfigClie.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CMDconfigClieActionPerformed(evt);
            }
        });
        JDesk.add(CMDconfigClie);
        CMDconfigClie.setBounds(20, 240, 210, 69);

        CMDCierreSesion.setText("Cerrar Sesion");
        CMDCierreSesion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                CMDCierreSesionActionPerformed(evt);
            }
        });
        JDesk.add(CMDCierreSesion);
        CMDCierreSesion.setBounds(873, 40, 110, 23);

        jScrollPane1.setViewportView(JDesk);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 1020, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 550, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void CMDBuscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CMDBuscarActionPerformed
        // TODO add your handling code here:
        if (this.buscar == true){
            //Aqui abriria la ventana de buscar usuario o generar reporte
            Supervisor sup = new Supervisor();
            JDesk.add(sup);
            sup.show();
        }
        else{
            JOptionPane.showMessageDialog(this, this.Error_Permiso);
        }
    }//GEN-LAST:event_CMDBuscarActionPerformed

    private void CMDServActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CMDServActionPerformed
        // TODO add your handling code here:
        if(this.modificar_servicio == true){
            //Aqui abriria la ventana de modificar servicios
            Ejecutivo e = new Ejecutivo();
            JDesk.add(e);
            e.setModDeuda(this.modificar_general);
            e.show();
        }
        else{
            JOptionPane.showMessageDialog(this, this.Error_Permiso);
        }
    }//GEN-LAST:event_CMDServActionPerformed

    private void CMDconfigUserActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CMDconfigUserActionPerformed
        // TODO add your handling code here:
        if(this.modificar_general == true){
            //Aqui abriria la ventana de modificar Usuarios
            Administracion Admn = new Administracion();
            JDesk.add(Admn);
            Admn.show();
        }
        else{
            JOptionPane.showMessageDialog(this, this.Error_Permiso);
        }
    }//GEN-LAST:event_CMDconfigUserActionPerformed

    private void CMDconfigClieActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CMDconfigClieActionPerformed
        // TODO add your handling code here:
        if(this.modificar_general == true){
            //Aqui abriria la ventana de modificar Clientes
            Admin Ad = new Admin();
            JDesk.add(Ad);
            Ad.show();
        }
        else{
            JOptionPane.showMessageDialog(this, this.Error_Permiso);
        }
    }//GEN-LAST:event_CMDconfigClieActionPerformed

    private void CMDCierreSesionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CMDCierreSesionActionPerformed
        // TODO add your handling code here:
        Login l = new Login();
        this.c = null;
        this.modificar_general = false;
        this.modificar_servicio = false;
        this.buscar = false;
        l.show();
        dispose();
    }//GEN-LAST:event_CMDCierreSesionActionPerformed

    private void formWindowOpened(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowOpened
        // TODO add your handling code here:
//        fondo();
    }//GEN-LAST:event_formWindowOpened
    public void fondo(){
        //imagen fondo
       ((JPanel) getContentPane()).setOpaque(false);
       ImageIcon imagen = new ImageIcon(this.getClass().getResource("/proyectocallcentergrupo6/ComunicateLogo5.png"));
       JLabel fondo = new JLabel();
       fondo.setIcon(imagen);
       getLayeredPane().add(fondo, JLayeredPane.FRAME_CONTENT_LAYER);
       fondo.setBounds(0, 0, imagen.getIconWidth(), imagen.getIconHeight());
       this.add(fondo, BorderLayout.CENTER);
       this.setSize(fondo.getWidth(), fondo.getHeight());
       this.setLocationRelativeTo(null);
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MenuGeneral.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MenuGeneral.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MenuGeneral.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MenuGeneral.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MenuGeneral().setVisible(true);
            }
        });
        
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton CMDBuscar;
    private javax.swing.JButton CMDCierreSesion;
    private javax.swing.JButton CMDServ;
    private javax.swing.JButton CMDconfigClie;
    private javax.swing.JButton CMDconfigUser;
    private javax.swing.JDesktopPane JDesk;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables
}
